package com.snopy.concurrency.join;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Demojoin
 * @description
 * @email 77912204@qq.com
 * @date 2022/07/03 20:11
 */
@Slf4j
public class Demojoin {
    static ExecutorService service = Executors.newFixedThreadPool(2);
    public static void main(String[] args) throws InterruptedException, ExecutionException {
        Thread t1 = new Thread(()->{
            log.debug("t1 begin...");
            try {
                log.debug("3 t1 is alive:{}",Thread.currentThread().isAlive());
                    TimeUnit.SECONDS.sleep(3);
                    log.debug("t1 end...");


            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1");
        Thread t2 = new Thread(()->{
            log.debug("t2 begin...");
            try {

                TimeUnit.SECONDS.sleep(1);
                log.debug("t2 end...");


            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t2");

        t1.start();
        TimeUnit.MILLISECONDS.sleep(10);
        t1.interrupt();

        /*synchronized (t1){
            while (t1.isAlive()){
                t1.wait(0);
            }
        }*/
        service.submit(t2);

    }
}

@Slf4j
class MyThread implements Runnable{

    @Override
    public void run() {
        log.debug("start...");
        try {
            TimeUnit.SECONDS.sleep(3);
            log.debug("end...");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


